/**
 * 
 */
package np.com.baralsujan.login.da;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * @author sujan
 *
 */
public class SessionFactoryUtil {
	
	private static SessionFactory sessionFactory;
	
	private SessionFactoryUtil() {
		
	}
	
	public static SessionFactory getInstance() {
		return sessionFactory;
	}
	
	static {
		sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
	}
	
	public Session openSession() {
		return sessionFactory.openSession();
	}
	
	public Session currentSession() {
		return sessionFactory.getCurrentSession();
	}
	
	public void close() {
		if (sessionFactory != null) {
			sessionFactory.close();
			sessionFactory = null;
		}
	}

}
